/*******************************************************************************
**			One Bad Apple Spoils the Bunch - Social Science Quarterly 		  **
**					Nathan T. Carrington & Colin French						  **
**							VOTER Dataset Replication						  **
*******************************************************************************/

//NOTE: Upon publication, we were made aware of some errors in the coding below. The errors include:
//using the aweights command instead of pweights, incorrectly coding the race variable, using a race variable from an earlier wave, and incorrectly labeling a variable in the figure. ]
//None of these errors impact the conclusions drawn from the analyses.
//Given the errors, the first section of this do-file replicates the exact analysis present in the paper while the second part highlights and fixes the errors noted. 


/*******************************************************************************
**								ORIGINAL ANALYSIS							  **
*******************************************************************************/

clear

set more off



//use "/Users/Nathan/Dropbox/Research/Law and Courts/Supreme Court/Individual Justice Evaluations and Legitimacy/Observational/2019VOTER/Raw_2019_VOTER.dta"


gen demsatisfaction=(satisf_dem_2018)
recode demsatisfaction (8=.) (1=4) (2=3) (3=2) (4=1)
gen demsatis_0to1=((demsatisfaction-1)/3)

recode race_majority_1_2016 (8=.) 

gen DemValues=(race_majority_1_2016+demsatisfaction)
gen DemValues_0to1=((DemValues-2)/6)

gen kavanaugh=(fav_kavanaugh_2019)
recode kavanaugh (8=.) (98=.) (1=4) (2=3) (3=2) (4=1)
gen kavanaugh_0to1=((kavanaugh-1)/3)

label define kavanaw2 0 "Unfavorable" 1 "Favorable"
label values kavanaugh_0to1 kavanaw2


gen SCOTUS_Confidence=inst_court_2019
recode SCOTUS_Confidence (8=.) (1=4) (2=3) (3=2) (4=1)

gen TermLimits=supreme1_2019
recode TermLimits (8=.) (5=.) 
gen TermLimits_0to1=((TermLimits-1)/3)


gen ExpandCourt=supreme2_2019
recode ExpandCourt (8=.) (5=.) 
gen ExpandCourt_0to1=((ExpandCourt-1)/3)


gen SCLegit=((TermLimits_0to1+ExpandCourt_0to1)/2)


gen TermLimitsREV=supreme1_2019
recode TermLimitsREV (8=.) (5=.) (1=4) (2=3) (3=2) (4=1)
gen TLimits_0to1=((TermLimitsREV-1)/3)


gen ExpandCourtREV=supreme2_2019
recode ExpandCourtREV (8=.) (5=.) (1=4) (2=3) (3=2) (4=1)
gen ECourt_0to1=((ExpandCourtREV-1)/3)










recode pid7_2019 (8=.)

gen Republican_0to1=((pid7_2019-1)/6)

label define pid 0 "Strong Democrat" 1 "Strong Republican"
label values Republican_0to1 pid

gen Age=(2019-birthyr_2019)
gen Age_0to1=((Age-19)/75)

gen Black=1 if race_2016==2 //NOTE: see correction below
replace Black=0 if race_2016==1 //NOTE: see correction below

gen Female=gender_2019
recode Female (1=0) (2=1)

recode ideo5_2019 (6=.) (8=.)
gen Conservative=ideo5_2019
gen Conservative_0to1=((Conservative-1)/4)

recode faminc_new_2019 (97=.) (98=.)
gen Income_0to1=((faminc_new_2019-1)/15)

recode pk_SCJ_baseline (8=.) (9=.)

gen KnowCourt=1 if pk_SCJ_baseline==5
replace KnowCourt=0 if pk_SCJ_baseline!=5

gen Educ_0to1=((educ_2019-1)/5)

gen FordTruth=0 if truth_2019==2
replace FordTruth=1 if truth_2019==1

recode newsint_2019 (7 8=.) (1=4) (2=3) (3=2) (4=1)
gen PoliticalInterest_0to1=((newsint_2019-1)/3)

recode inst_court_2018 (8=.) (1=4) (2=3) (3=2) (4=1)
gen SCConfidence2018=((inst_court_2018-1)/3)

recode inst_court_2019 (8=.) (1=4) (2=3) (3=2) (4=1)
gen SCConfidence2019=((inst_court_2019-1)/3)

recode watchtv_baseline (8 9=.)
gen WatchTV_0to1=((watchtv_baseline-1)/3)

gen KavanaughTrue=1 if truth_2019==2
replace KavanaughTrue=0 if truth_2019==1
replace KavanaughTrue=0 if truth_2019==8

gen RuleLaw1=1 if pres_obey_courts_2017==2
replace RuleLaw1=0 if pres_obey_courts_2017==1

recode amgovt_2016 (8 98=.) (4=1) (3=2) (2=3) (1=4)
gen RuleofLaw=((amgovt_2016-1)/3)
label define RL 0 "Not Important" 1 "Very Important" 
label values RuleofLaw RL

gen KavPID=kavanaugh_0to1*Republican_0to1
 

*******MODEL 1: Combined Diffuse Support********
reg SCLegit kavanaugh_0to1 demsatis_0to1 Age_0to1 Republican_0to1 Black Female Educ_0to1 Conservative_0to1 KnowCourt RuleofLaw [aw=weight_2019]
estimates store M1_Diffuse

*******MODEL 2: Expand Court********
reg ECourt_0to1 kavanaugh_0to1 demsatis_0to1 Age_0to1 Republican_0to1 Black Female Educ_0to1 Conservative_0to1 KnowCourt RuleofLaw  [aw=weight_2019]
estimates store M2_Expand

*******MODEL 2: Term Limits********
reg TLimits_0to1 kavanaugh_0to1 demsatis_0to1 Age_0to1 Republican_0to1 Black Female Educ_0to1 Conservative_0to1 KnowCourt RuleofLaw [aw=weight_2019]
estimates store M3_Term




*****FIGURE 1*************
 #delimit ;
	coefplot M1_Diffuse,
	xline(0) 
	drop(_cons)
	title("Study 1: Correlates of Supreme Court Diffuse Support", color(black) size() span)
	xtitle("Coefficients")
	//nolabels
	coeflabels(
		kavanaugh_0to1 = "Kavanaugh Affect"
		demsatis_0to1 = "Democratic Satisfaction"
		Age_0to1 = "Birth Year"
		Republican_0to1 = "Republican"
		Black = "Black"
		Female = "Female"
		Conservative_0to1 = "Conservative"
		KnowCourt = "Knows Court"
		Educ_0to1 = "Education"
		RuleofLaw = "Rule of Law"
		)
	plotlabels(
	)
	//nokey
	note("Source: 2019 Views of the Electorate Research Survey. N=3,316", size(vsmall) span)
	//graphregion(color(white))
	scheme(plotplain)
	;
	
	


***FIGURE 2**
reg SCLegit kavanaugh_0to1 demsatis_0to1 Age_0to1 Republican_0to1 Black Female Educ_0to1 Conservative_0to1 KnowCourt RuleofLaw [aw=weight_2019]
quietly margins, at(kavanaugh_0to1=(0(.25)1))
#delimit ;
marginsplot,  
	title("Study 1: Predicted Institutional Support for the Supreme Court by Kavanaugh Favorability", color(black) span)
	xtitle("Kavanaugh Favorability")
	ytitle("Predicted Institutional Support")
	note("Source: 2019 Views of the Electorate Research Survey. N=3,316", size(vsmall) span)
	//plotopts(connect(i))
	xlabel()
	scheme(plotplain)
	graphregion(margin(r=10))
	//noci
	name(ds_predicted, replace)
	;

 
***FIGURE 3**
reg SCLegit c.kavanaugh_0to1##c.Republican_0to1 demsatis_0to1 Age_0to1 Black Female Educ_0to1 Conservative_0to1 KnowCourt RuleofLaw [aw=weight_2019]
quietly margins, at(kavanaugh_0to1=(0(.25)1) Republican_0to1=(0 1))
#delimit ;
marginsplot,  
	title("Study 1: Heterogeneous Effects by Partisanship", color(black) span)
	xtitle("Kavanaugh Favorability")
	ytitle("Predicted Institutional Support")
	note("Source: 2019 Views of the Electorate Research Survey. N=3,316", size(vsmall) span)
	//plotopts(connect(i))
	xlabel()
	scheme(plotplain)
	graphregion(margin(r=10))
	//noci
	name(ds_predicted, replace)
	;






/////////////ROBUSTNESS CHECK
*******MODEL 1: Combined Diffuse Support********
reg SCLegit kavanaugh_0to1 demsatis_0to1 Age_0to1 Republican_0to1 Black Female Educ_0to1 Conservative_0to1 KnowCourt PoliticalInterest_0to1 SCConfidence2018 SCConfidence2019 KavanaughTrue RuleofLaw [aw=weight_2019]
estimates store M1_Robust


*****GRAPHS*************
 #delimit ;
	coefplot M1_Robust,
	xline(0) 
	drop(_cons)
	title("Study 1: Correlates of Supreme Court Diffuse Support", color(black) size() span)
	xtitle("Coefficients")
	//nolabels
	coeflabels(
		kavanaugh_0to1 = "Kavanaugh Affect"
		demsatis_0to1 = "Democratic Satisfaction"
		Age_0to1 = "Birth Year"
		Republican_0to1 = "Republican"
		Black = "Black"
		Female = "Female"
		Conservative_0to1 = "Conservative"
		KnowCourt = "Knows Court"
		Educ_0to1 = "Education"
		PoliticalInterest_0to1 = "Political Interest"
		SCConfidence2018 = "2018 SCOTUS Confidence"
		SCConfidence2019 = "2019 SCOTUS C0nfidence"
		KavanaughTrue = "Kavanaugh Tell Truth"
		RuleofLaw = "Rule of Law"
		)
	plotlabels(
	)
	//nokey
	note("Source: 2019 Views of the Electorate Research Survey. N=3,316", size(vsmall) span)
	//graphregion(color(white))
	scheme(plotplain)
	;
	
	


	
	
	
	
	
	
/*******************************************************************************
**							CORRECTED ANALYSIS								  **
*******************************************************************************/
//This section corrects the following errors in the above coding:
//1) The analysis relied on the race variable from an earlier wave (race_2016) and not one from teh current wave (race_2019)
//2) Instead of coding all non-Black respondents as zero, the coding accidentally collapsed race into a Black/White binary, excluding hundreds of respondents.
//3) The analysis was conducted using the analytical weights (awweights) command instead of the probability weights (pweights) command, affecting confidence intervals;
//4) The "Birth Year" variable in the graphs should be renamed "Age";
//The authors regret these errors.


	
	

//NEW RACE VARIABLE
gen NewBlackVar=1 if race_2019==2
replace NewBlackVar=0 if race_2019!=2
replace NewBlackVar=. if race_2019==.


 

*******MODEL 1: Combined Diffuse Support********
reg SCLegit kavanaugh_0to1 demsatis_0to1 Age_0to1 Republican_0to1 NewBlackVar Female Educ_0to1 Conservative_0to1 KnowCourt RuleofLaw [pw=weight_2019] //Corrects race variable and weights command
estimates store M1_Diffuse

*******MODEL 2: Expand Court********
reg ECourt_0to1 kavanaugh_0to1 demsatis_0to1 Age_0to1 Republican_0to1 NewBlackVar Female Educ_0to1 Conservative_0to1 KnowCourt RuleofLaw  [pw=weight_2019] //Corrects race variable and weights command
estimates store M2_Expand

*******MODEL 2: Term Limits********
reg TLimits_0to1 kavanaugh_0to1 demsatis_0to1 Age_0to1 Republican_0to1 NewBlackVar Female Educ_0to1 Conservative_0to1 KnowCourt RuleofLaw [pw=weight_2019] //Corrects race variable and weights command
estimates store M3_Term




*****FIGURE 1*************
 #delimit ;
	coefplot M1_Diffuse,
	xline(0) 
	drop(_cons)
	title("Study 1: Correlates of Supreme Court Diffuse Support", color(black) size() span)
	xtitle("Coefficients")
	//nolabels
	coeflabels(
		kavanaugh_0to1 = "Kavanaugh Affect"
		demsatis_0to1 = "Democratic Satisfaction"
		Age_0to1 = "Age" //RENAMED VARIABLE
		Republican_0to1 = "Republican"
		Black = "Black"
		Female = "Female"
		Conservative_0to1 = "Conservative"
		KnowCourt = "Knows Court"
		Educ_0to1 = "Education"
		RuleofLaw = "Rule of Law"
		)
	plotlabels(
	)
	//nokey
	note("Source: 2019 Views of the Electorate Research Survey. N=3,316", size(vsmall) span)
	//graphregion(color(white))
	scheme(plotplain)
	;
	
	


***FIGURE 2**
reg SCLegit kavanaugh_0to1 demsatis_0to1 Age_0to1 Republican_0to1 NewBlackVar Female Educ_0to1 Conservative_0to1 KnowCourt RuleofLaw [pw=weight_2019]
quietly margins, at(kavanaugh_0to1=(0(.25)1))
#delimit ;
marginsplot,  
	title("Study 1: Predicted Institutional Support for the Supreme Court by Kavanaugh Favorability", color(black) span)
	xtitle("Kavanaugh Favorability")
	ytitle("Predicted Institutional Support")
	note("Source: 2019 Views of the Electorate Research Survey. N=3,316", size(vsmall) span)
	//plotopts(connect(i))
	xlabel()
	scheme(plotplain)
	graphregion(margin(r=10))
	//noci
	name(ds_predicted, replace)
	;

 
***FIGURE 3**
reg SCLegit c.kavanaugh_0to1##c.Republican_0to1 demsatis_0to1 Age_0to1 Black Female Educ_0to1 Conservative_0to1 KnowCourt RuleofLaw [pw=weight_2019]
quietly margins, at(kavanaugh_0to1=(0(.25)1) Republican_0to1=(0 1))
#delimit ;
marginsplot,  
	title("Study 1: Heterogeneous Effects by Partisanship", color(black) span)
	xtitle("Kavanaugh Favorability")
	ytitle("Predicted Institutional Support")
	note("Source: 2019 Views of the Electorate Research Survey. N=3,316", size(vsmall) span)
	//plotopts(connect(i))
	xlabel()
	scheme(plotplain)
	graphregion(margin(r=10))
	//noci
	name(ds_predicted, replace)
	;

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
